<template>
	<view class="">
		<view class="tabbar" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}" v-show="isblack">
			<view class="tabbar-item flexcenter" v-for="(item, index) in list" :key="index" @click="tabbarChange(item.path,index)">
				<view class="flexleft huibiao" v-if="index==3">
					<u-badge max="99" :value="noreadNum"></u-badge>
				</view>
				<view class="item-name" v-if="item.text" :class="{'tabbarActive': current == index}">{{item.text}}
				</view>
				<view class="addimg" v-else>
					<u-icon name="plus" color="#fff" size="15"></u-icon>
				</view>
			</view>
		</view>
		<view class="tabbar" style="background-color: #fff;" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}" v-show="!isblack">
			<view class="tabbar-item flexcenter" v-for="(item, index) in list" :key="index" @click="tabbarChange(item.path,index)">
				<view class="flexleft huibiao" v-if="index==3">
					<u-badge max="99" :value="noreadNum"></u-badge>
				</view>
				<view class="item-name" v-if="item.text" :class="{'tabbarActive2': current == index}">{{item.text}}
				</view>
				<view class="addimg" style="border-color: #000;" v-else>
					<u-icon name="plus" color="#000" size="15"></u-icon>
				</view>
			</view>
		</view>
		<yk-authpup ref="authpup" type="top" @changeAuth="changeAuth" :permissionID="permissionID"></yk-authpup>
	</view>
	
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")
	import ykAuthpup from "@/components/yk-authpup/yk-authpup";
	export default {
		name: "tabbardi",
		components: {
			ykAuthpup
		},
		props: ['current',"isblack"],
		data() {
			return {
				paddingBottomHeight: 0, //苹果X以上手机底部适配高度
				list: [{
						text: '首页',
						path: "/pages/homepage", //页面路径
					},
					{
						text: '动态',
						path: "/pages/dongtai", //页面路径
					},
					{
						text: '',
						path: "/pages/ox", //页面路径
					},
					{
						text: '消息',
						path: "/pages/message", //页面路径
					},
					{
						text: '我的',
						path: "/pages/mypage", //页面路径
					}
				],
				permissionID:"",
				sourceType: ['camera'],
				noreadNum:0,
			}
		},
		// created() {
		// 	let that = this;
		// 	uni.getSystemInfo({
		// 		success: function(res) {
		// 			let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
		// 			model.forEach(item => {
		// 				//适配iphoneX以上的底部，给tabbar一定高度的padding-bottom
		// 				if (res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
		// 					that.paddingBottomHeight = 0;
		// 				}
		// 			})
		// 		}
		// 	});
		// },
		mounted() {
			uni.$on("updatechatFnteList", data => {
				console.log("别人给我发消息触发方法了");
				this.getnoreadNum()
			})
		},
		destroyed() {
			uni.$off('updatechatFnteList')
		},
		created() {
			this.getnoreadNum()
		},
		methods: {
			getnoreadNum(){
				if (!httpRequest.checkIsLogin()) {
					return false;
				}
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.noreadNum = res.data.total_noread_num
					console.log(res.data.total_noread_num);
				})
			},
			tabbarChange(path,index) {
				let _this = this
				if(index == this.current){
					return false
				}
				let url = getApp().globalData.videopage
				if(index==0){
					uni.switchTab({
						url
					})
					return false
				}
				if(index==2 || index==3 || index==4){
					if (!httpRequest.checkIsLogin()) {
						uni.navigateTo({
							url: "/pages/login/login"
						})
						return false;
					}
				}
				if(index==2){
					uni.setStorageSync("lastpage", this.list[this.current].path)
				}
				if (index == 2 && !uni.getStorageSync("ysq") && uni.getSystemInfoSync().platform != 'ios') {
					let _this = this
					_this.openAuth('CAMERA');
					_this.sourceType = ['camera'];
					return false
				}
				uni.switchTab({
					url: path
				})
			},
			openAuth(permissionID) {
				this.permissionID =
				permissionID; //这个是对应的权限 ACCESS_FINE_LOCATION 位置权限 / WRITE_EXTERNAL_STORAGE 存储空间/照片权限 / CAMERA相机权限 / CALL_PHONE 拨打电话
				setTimeout(() => {
					this.$refs['authpup'].open();
				}, 500)
			},
			changeAuth(){
				let _this = this;
				// 选择相机走0
				if (this.sourceType=="camera") {
					_this.openAuth('WRITE_EXTERNAL_STORAGE');
					_this.sourceType=['album'];
					return false
				}
				// 选择相册走1
				if (this.sourceType=="album") {
					_this.openAuth('RECORD_AUDIO');
					_this.sourceType=['audio'];
					return false
				}
				if (this.sourceType=="audio") {
					uni.setStorageSync("ysq",true)
					uni.switchTab({
						url: "/pages/ox"
					})
				}
			},
		}

	}
</script>

<style lang="scss">
	.huibiao{
		position: absolute;
		right: 5rpx;
		top: 0rpx;
	}
	.addimg {
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 10rpx 30rpx;
		margin-top: 14rpx;
		border-radius: 50rpx;
		border: 6rpx solid #fff;
		width: 100rpx;
	}

	.item-img1 {
		height: 83rpx;
		width: 200rpx;
		margin: auto;
		display: block;
	}

	.item-img {
		height: 36rpx;
		width: 98rpx;
		margin: auto;
		display: block;
	}

	// .fabuimg{
	// 	position: absolute;
	// 	bottom: 36rpx;
	// 	left: 10rpx;
	// 	height: 90rpx;
	// 	width: 90rpx;
	// 	margin: auto;
	// 	display: block;
	// 	background-color: #fff;
	// 	background-size: 80rpx 80rpx;
	// 	border-radius: 50%;
	// 	// box-shadow: 0px -5px 5px 0px rgba(0, 0, 0, 0.05);
	// }

	.tabbar {
		display: flex;
		justify-content: space-between;
		// align-items: flex-end;
		align-items: center;
		background: #000;
		border-radius: 0rpx;
		/* #ifdef MP-WEIXIN */
		height: 140rpx;
		/* #endif */
		/* #ifdef H5 */
		height: 140rpx;
		/* #endif */
		/* #ifdef APP-PLUS */
		height: 140rpx;
		/* #endif */
		// padding: 0 50rpx 0 50rpx;
		box-sizing: border-box;
		position: fixed;
		width: 100%;
		bottom: 0;
		left: 0;
		overflow: inherit;
		z-index: 1000;
		// box-shadow: 0px -2px 4px 1px rgba(0, 0, 0, 0.05);
	}

	.tabbar-item {
		margin-bottom: 30rpx;
		width: 150rpx;
		position: relative;
		box-sizing: border-box;
	}

	.item-name {
		font-size: 32rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		text-align: center;
		color: #A3A3A3;
		margin-top: 14rpx;
	}

	.tabbarActive {
		color: #fff;
		font-weight: bold;
		text-align: center;
	}
	.tabbarActive2{
		color: #000;
		font-weight: bold;
		text-align: center;
	}

	/deep/.time__custom {
		width: 80rpx !important;
	}
</style>